package com.snbc.string;

public class Demo1 {
    public static void main(String[] args) {
        String sentence = "盖伦,在进行了连续8次击杀后,获得了“超神”的称号";

        //截取从第3个开始的字符串
        String subString1 = sentence.substring(3);
        //System.out.println(subString1);
        //在进行了连续8次击杀后,获得了 超神 的称号

        //截取 从第3个开始到第5个结束的位置的字符串，3-5 不包括5。左闭右开
        String subString2 = sentence.substring(3, 5);
        // System.out.println(subString2);
        //在进

        /*
        split
        根据分隔符进行分隔,分隔出来后 返回的是一个数组，将分隔出来的内容放在数组内，若要取出，必须要对数组进行遍历
        */
/*        String[] subSentense = sentence.split(",");
        for (String ss : subSentense
        ) {
            System.out.println(ss);
        }*/

        /*去掉首尾空格*/
/*        String sentence1 = "     盖伦,在进行了连续8次击杀后,获得了“超神”的称号        ";
        System.out.println(sentence1.trim());

        String sentence2 = "abc";
        String sentence3 = "ABC";
        System.out.println(sentence2.toUpperCase());//提升为大写
        System.out.println(sentence3.toLowerCase());//转化为为小写
        System.out.println(sentence.contains("超神"));//是否包含字符串"超神"*/
        /*
        替换
        *replaceAll： 全部替换:第一个参数被替换的字符串，第二个参数需要替换的新串
        *replaceFirst:只替换第一个
        */
/*
        String tem = sentence.replaceAll("超神", "超鬼");
        System.out.println(tem);
        String tem1 = sentence.replaceFirst(",", "1");
        System.out.println(tem1);
*/
        /*将每个单词的首字母转换位大写
         * 1把每个单词分离出来： 用split
         * 2 对分离出来的每个单词取首字母charAt（0）
         * 3 首字母转换为大写toUpperCase
         * 4 拼接上剩下的字符 substring(1)
         *使用for循环
         */
/*        String abc = "right right go go go";
        String[] temp = abc.split(" ");
        for (String aa : temp
        ) {
            char first = aa.charAt(0);
            //System.out.println(first);
            String up = String.valueOf(first).toUpperCase();
            StringBuilder sb = new StringBuilder();
            sb.append(up + aa.substring(1));
            System.out.print(sb + " ");
        }
        System.out.println();*/
        /*
         *查看 a-z A-Z 对应的ASCII码
         * A-65 a-97
         */
        // char ch = 'A';
        // short s = (short) ch;
        // System.out.println(ch + ":" + s);
        //Total();
        //间隔大小写
        String aaqa = "wfdfsfdsfdsfs";
        char[] ch = aaqa.toCharArray();
        for (int i = 0; i <= ch.length; i++) {
            if (i % 2 == 0) {
                ch[i] = Character.toUpperCase(ch[i]);
            }
        }
        String value = String.valueOf(ch);
        System.out.println(value);
    }

    /*
     * peter piper picked a peck of pickled peppers
     *统计这段绕口令有多少个以p开头的单词
     * */
    private static void Total() {
        String aa = "peter piper picked a peck of pickled peppers";
        String[] fegen = aa.split(" ");
        int count = 0;
        for (String s1 : fegen
        ) {
            char first = s1.charAt(0);
            if (String.valueOf(first).contains("p")) {
                count++;
            }
        }
        System.out.println(count);
    }
}
